package com.lvmama.core.service;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.lvmama.core.bean.UserTravelDetail;
import com.lvmama.core.bean.UserTravelDetailDTO;
import com.lvmama.core.bean.UserTravelDetailQuery;
import com.lvmama.core.bean.base.ResultBase;
import com.lvmama.core.dao.UserTravelDetailDao;
import com.lvmama.enums.ErrorCodeEnum;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户旅行service实现类
 * 
 * @author caoyong
 * @since 2018年6月21日 上午10:56:02
 */
@Slf4j
@Service(version = "1.0.0")
public class UserTravelServiceImpl implements UserTravelService {

    @Autowired
    private UserTravelDetailDao userTravelDetailDao;

    @Override
    public ResultBase<List<UserTravelDetail>> selectUserTravelDetailByQuery(UserTravelDetailDTO query) {
        log.info("selectUserTravelDetailByQuery start, query:{}",
                ToStringBuilder.reflectionToString(query, ToStringStyle.DEFAULT_STYLE));
        ResultBase<List<UserTravelDetail>> result = new ResultBase<>();
        try {
            UserTravelDetailQuery example = new UserTravelDetailQuery();
            example.setPageNo(query.getPageNo());
            example.setPageSize(query.getLimit());
            List<UserTravelDetail> details = userTravelDetailDao.selectByExampleWithBLOBs(example);
            result.setValue(details);
            if (details != null && !details.isEmpty()) {
                result.setSuccess(true);
            }
        } catch (Exception e) {
            result.setErrorCode(ErrorCodeEnum.UNKOWN_ERROR.getCode());
            result.setErrorMsg(ErrorCodeEnum.UNKOWN_ERROR.getMsg());
            log.error("queryRoleList error:", e.getMessage(), e);
        }
        log.info("selectUserTravelDetailByQuery end.");
        return result;
    }

}
